home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’96 / PredatorPrey / Scrolling.c < prev    next >
Text File  |  1996-06-22  |  4KB  |  150 lines

  1. /* © 1988-91, Bowers Development Corp. */
  2. /* Scrolling.c */
  3.  
  4. #include <Types.h>
  5. #include <Quickdraw.h>
  6. #include <Controls.h>
  7. #include <Dialogs.h>
  8. #include <Events.h>
  9. #include <Lists.h>
  10. #include <Menus.h>
  11. #include <TextEdit.h>
  12. #include "Globals.h"    
  13.  
  14. #include "Scrolling.h"
  15.  
  16. void    ScrollingSeg()    {}
  17.  
  18. #pragma segment Scrolling
  19.     
  20. /*----------*/
  21. void ResizeScrollBars    ()
  22. {
  23.     Rect            contrlRect;
  24.     short            curTop;
  25.     short            curLeft;
  26.     Rect            portRect;
  27.     
  28.     portRect = curWindow->portRect;
  29.     if (cur->vScroll != NULL) {
  30.         contrlRect = (**(cur->vScroll)).contrlRect;
  31.         curTop = contrlRect.top;
  32.         HideControl (cur->vScroll);
  33.         MoveControl (cur->vScroll,
  34.                      (portRect.right + 1) - sBarWidth,
  35.                      curTop);
  36.         SizeControl (cur->vScroll,
  37.                      sBarWidth,
  38.                      ((portRect.bottom + 1) - sBarWidth) + 1 - curTop);
  39.         ShowControl (cur->vScroll);
  40.         contrlRect = (**(cur->vScroll)).contrlRect;
  41.         ValidRect (&contrlRect);
  42.     }
  43.     
  44.     if (cur->hScroll != NULL) {
  45.         contrlRect = (**(cur->hScroll)).contrlRect;
  46.         curLeft = contrlRect.left;
  47.         HideControl (cur->hScroll);
  48.         MoveControl (cur->hScroll,
  49.                      curLeft,
  50.                      (portRect.bottom + 1) - sBarWidth);
  51.         SizeControl (cur->hScroll,
  52.                      ((portRect.right + 1) - sBarWidth) + 1 - curLeft,
  53.                      sBarWidth);
  54.         ShowControl (cur->hScroll);
  55.         contrlRect = (**(cur->hScroll)).contrlRect;
  56.         ValidRect (&contrlRect);
  57.     }
  58. } /*ResizeScrollBars*/
  59.  
  60. /*----------*/
  61. void DoScrollPart    (ControlHandle    whichScroll,
  62.                      short            partCode)
  63. {
  64.     short            pageSize;
  65.     short            delta;
  66.     short            oldValue;
  67.  
  68.     pageSize = GetCRefCon (whichScroll);
  69.     switch (partCode) {
  70.     case inUpButton:
  71.             delta = -1;
  72.         break;
  73.     case inDownButton:
  74.             delta = 1;
  75.         break;
  76.     case inPageUp:
  77.             delta = -pageSize;
  78.         break;
  79.     case inPageDown:
  80.             delta = pageSize;
  81.         break;
  82.     default:
  83.             delta = 0;
  84.         break;
  85.     } /*switch*/
  86.     if (delta != 0) {
  87.         oldValue = GetCtlValue (whichScroll);
  88.         SetCtlValue (whichScroll, oldValue + delta);
  89.     }
  90. } /*DoScrollPart*/
  91.     
  92. /*----------*/
  93. pascal void ActionGlue    (ControlHandle    whichScroll,
  94.                          short            partCode);
  95. pascal void ActionGlue    (ControlHandle    whichScroll,
  96.                          short            partCode)
  97. {
  98.     short            oldValue;
  99.     short            newValue;
  100.     ScrollProcPtr    actionProc;
  101.  
  102.     oldValue = GetCtlValue (whichScroll);
  103.     DoScrollPart (whichScroll, partCode);
  104.     newValue = GetCtlValue (whichScroll);
  105.     if (newValue != oldValue) {
  106.         actionProc = (ScrollProcPtr) (**whichScroll).contrlAction;
  107.         (*actionProc) (newValue, oldValue);
  108.     }
  109. } /*ActionGlue*/
  110.  
  111. /*----------*/
  112. void TrackScroll    (ControlHandle    whichScroll,
  113.                      short            partCode,
  114.                      Point            where,
  115.                      ScrollProcPtr    actionProc)
  116. {
  117.     short            oldValue;
  118.     short            newValue;
  119.     ControlActionUPP    actionUPP;
  120.     
  121.     if (partCode == inThumb) {
  122.         oldValue = GetCtlValue (whichScroll);
  123.         partCode = TrackControl (whichScroll, where, NULL);
  124.         if (actionProc != NULL) {
  125.             newValue = GetCtlValue (whichScroll);
  126.             (*actionProc) (newValue, oldValue);
  127.         }
  128.     } else {
  129.         if (actionProc == NULL) {
  130.             partCode = TrackControl (whichScroll, where, NULL);
  131.             DoScrollPart (whichScroll, partCode);
  132.         } else {
  133.             #ifdef      powerc
  134.                 (**whichScroll).contrlAction = (UniversalProcPtr) actionProc;
  135.                 partCode = TrackControl (whichScroll, where, (UniversalProcPtr) &ActionGlue);
  136.             #else
  137.                 (**whichScroll).contrlAction = (ControlActionProcPtr) actionProc;
  138.                 actionUPP = NewControlActionProc (ActionGlue);
  139.                 partCode = TrackControl (whichScroll, where, actionUPP);
  140.                 DisposeRoutineDescriptor ((UniversalProcPtr) actionUPP);
  141.             (**whichScroll).contrlAction = NULL;
  142.             #endif      /* powerc */    
  143.  
  144.         
  145.         }
  146.     }
  147. } /*TrackScroll*/
  148.  
  149. /* Scrolling */
  150.